package com.atguigu.gmall.order.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.mq.ware.WareStock;
import com.atguigu.gmall.order.biz.OrderBizService;
import com.atguigu.gmall.order.vo.OrderSplitRespVo;
import com.atguigu.gmall.order.vo.OrderSubmitVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RequestMapping("/api/order")
@RestController
public class OrderApiController {
    @Autowired
    private OrderBizService  orderBizService;


   @PostMapping("/auth/submitOrder")
    public Result submitOrder(@RequestParam("tradeNo") String tradeNo,
                              @Valid @RequestBody OrderSubmitVo submitVo){
       // TODO 下单方法 雪花算法生成的大id，一定要以字符串的方式返回回去
      Long orderId=  orderBizService.submitOrder(tradeNo,submitVo);
      return  Result.ok(orderId+"");

    }

    /**
     * 订单拆分
     * @param orderId
     * @param json
     * @return
     */
    @PostMapping("/orderSplit")
    public List<OrderSplitRespVo> OrderSplit(@RequestParam("orderId")Long orderId,
                                             @RequestParam("wareSkuMap")  String json){
         //把一个大单拆分成多个小单
         List<OrderSplitRespVo>  splitRespVos= orderBizService.orderSplit(orderId,json);
         return splitRespVos;
     }

}
